iT邦幫忙

2025 iThome 鐵人賽

DAY 19
0
Cloud Native

我在 CKS 考完只拿 47% 後痛定思痛決定好好準備內容系列 第 19

[Day19] 5-1. Minimize base image footprint

  • 分享至 

  • xImage
  •  

今天主要是對 Docker image 的配置做討論,官方建議中需要符合以下項目

  • 最小化 container image 中不必要的內容。
  • Container image 應配置為以非特權使用者身份執行。
  • 對 container image 的引用應使用 sha256 digest(而非 tag),或透過 admission control 在部署時驗證 image 的數位簽章來驗證 image 的來源。
  • Container image 應在建立和部署期間定期掃描,並修補已知的有漏洞軟體。
# 使用具體版本的image
FROM ubuntu:24.04

RUN apt-get update && \
    apt-get install -y python3 python3-pip && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 建立非 root 使用者
RUN useradd -r -u 1000 -m -s /bin/sh appuser

WORKDIR /app

COPY requirements.txt /app/
RUN pip3 install --no-cache-dir -r requirements.txt

# 設定適當的檔案權限
COPY --chown=appuser:appuser app.py test_app.py entrypoint.sh /app/

RUN chmod +x /app/entrypoint.sh

# 使用非 root 使用者
USER appuser
EXPOSE 5000

ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["run"]

針對 image 檢查

sha512sum kube-apiserver 

參考文件
https://kubernetes.io/docs/concepts/security/security-checklist/


上一篇
[Day18] 4-4. Implement Pod-to-Pod encryption (Cilium, Istio)
下一篇
[Day20] 5-2. Understand your supply chain (e.g. SBOM, CI/CD, artifact repositories)
系列文
我在 CKS 考完只拿 47% 後痛定思痛決定好好準備內容25
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言